package edu.scau.mis.cloth.service.impl;

import edu.scau.mis.cloth.entity.GsDelivery;
import edu.scau.mis.cloth.dao.GsDeliveryDao;
import edu.scau.mis.cloth.service.GsDeliveryService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (GsDelivery)表服务实现类
 *
 * @author makejava
 * @since 2022-05-24 12:26:16
 */
@Service("gsDeliveryService")
public class GsDeliveryServiceImpl implements GsDeliveryService {
    @Resource
    private GsDeliveryDao gsDeliveryDao;


    public List<Map<String,Object>> queryAll(){
        return gsDeliveryDao.queryAll();
    }
    /**
     * 通过ID查询单条数据
     *
     * @param dvId 主键
     * @return 实例对象
     */
    @Override
    public GsDelivery queryById(Integer dvId) {
        return this.gsDeliveryDao.queryById(dvId);
    }


    public int insert(String orderId,int quantity){
        return  gsDeliveryDao.insert(orderId,quantity);
    }
    /**
     * 分页查询
     *
     * @param gsDelivery 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<GsDelivery> queryByPage(GsDelivery gsDelivery, PageRequest pageRequest) {
        long total = this.gsDeliveryDao.count(gsDelivery);
        return new PageImpl<>(this.gsDeliveryDao.queryAllByLimit(gsDelivery, pageRequest), pageRequest, total);
    }


    /**
     * 修改数据
     *
     * @param gsDelivery 实例对象
     * @return 实例对象
     */
    @Override
    public GsDelivery update(GsDelivery gsDelivery) {
        this.gsDeliveryDao.update(gsDelivery);
        return this.queryById(gsDelivery.getDvId());
    }

    /**
     * 通过主键删除数据
     *
     * @param dvId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer dvId) {
        return this.gsDeliveryDao.deleteById(dvId) > 0;
    }
}
